﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using Entidades.Karaoke;

namespace Datos.Caja
{
    public class CajPagoDAL
    {

        public static string cnx = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString();

        public static CajPago ValidaPagoServicio(int nroServicio)
        {
            System.Diagnostics.Debug.WriteLine("Valido pago select p.* from Caj_Pago p inner join Caj_Cuenta c on p.NumeroCuenta=c.NumeroCuenta and p.IdOrden=c.IdOrden inner join  Caj_Orden o on c.IdOrden=o.IdOrden where o.IdServicio="+nroServicio);
            SqlConnection con = new SqlConnection(cnx);
            SqlCommand com = new SqlCommand("select p.* from Caj_Pago p inner join Caj_Cuenta c on p.NumeroCuenta=c.NumeroCuenta and p.IdOrden=c.IdOrden inner join  Caj_Orden o on c.IdOrden=o.IdOrden where o.IdServicio=" + nroServicio, con);

            com.CommandType = System.Data.CommandType.Text;
            try
            {
                con.Open();
                SqlDataReader dr = com.ExecuteReader();
                CajPago obj = null;
                while (dr.Read())
                {
                    obj = new CajPago();

                    obj.IdOrden = (dr["IdOrden"].ToString());
                    obj.NumeroCuenta = Convert.ToInt32(dr["NumeroCuenta"].ToString());
                    obj.NumeroComprobante = (dr["NumeroComprobante"].ToString());
                    obj.TipoComprobante = (dr["TipoComprobante"].ToString());
                    obj.IdCupon = (dr["IdCupon"].ToString());
                  //  obj.FechaHoraEmision = Convert.ToDateTime(dr["FechaHoraEmision"].ToString());
                    obj.MostrarDetallePago = (Convert.ToBoolean(dr["MostrarDetallePago"]) ? 1 : 0);
                    obj.Total = Convert.ToDouble(dr["Total"].ToString());
                    obj.CodigoAdministrador = (dr["CodigoAdministrador"].ToString());
                  //  obj.FechaAnulacion = Convert.ToDateTime(dr["FechaAnulacion"].ToString());
                    obj.ConceptoAnulacion = (dr["ConceptoAnulacion"].ToString());
                }
                dr.Close();

                return obj;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);

                throw ex;
            }
            finally
            {
                con.Close();
            }
        }

    }
}
